home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: Correct usage of system call?
- Date: 29 Mar 1996 17:07:03 GMT
- Organization: OpenVision
- Message-ID: <4jh5bn$d56@spanky.pls.ov.com>
- References: <4jb03v$oi6@news.tamu.edu>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article oi6@news.tamu.edu, jrm4227@tam2000.tamu.edu (Justin Ray Mcelhanon) writes:
- > Alright here is the situation I need help with, can not figure out the
- >problem after at least three hours of trying to fix it. I have written a small
- >c code that is a menu that calls up unix commands using sytems:
- >
- >i.e)
- > printf ("1. Pine");
- > printf ("2. Usenet (tin)\n");
- > printf ("3. Ftp\n");
- >
- > scanf("%d", &choice);
- >
- > switch (choice)
- > {
- > case 1:
- > printf ("Executing Pine\n");
- > system("pine");
- > break;
- >
- >
- >It works great, however, I'd like to add in a command to allow one to
- >type in the site name. Example, when you call up the ftp case it does
- >a scanf(%s,site); (with site declared as an char string) anyway I then
- >want to take that and put it in the system command. ie system("ftp site"),
- >but that is not the proper syntax, how could I accomplish this? That will
- >not work, I tested to see if the system command would even accept variables
- >as input, so I tried system(&site); ( BTW system(site) kept giving segmentation
- >faults) this code would properly send the output to unix shell, however, if
- >a space is place in the string it only reads the first part, and it also
- >doesn't include ftp on the front. What is the proper syntax to mix C
- >variables and unix system calls? Mind you I've taught the little C and unix
- >I know from these news groups and such, so if something appears totally
- >wrong, it might be :) If you'd like a better explination of the problem,
- >or want more of the code, email me at thorin@tamu.edu, and if you reply,
- >please Carbon Copy me a response via mail because I don't trust the usenet
- >server, it plays Ollie North and cannot recall that post or reply. Okay
- >thanks for the help
- >
- >
- >--
- >****************************************** A! JW2 WAR+++ PI++ BR+++ SL+++ SK+
- >Yakko: "Well it's been fun friend, R&R++ GDF++ GP+++++ B&M++ HIP- SN+
- >but we've got to get back to HN+++! MS+ ME+ CB~ MM++! KK-- CO++
- >planet reality now" (Baloney and Friends) GLF-- P++ $++ E26 Ee10 TSlappy A18
- >Justin McElhanon----------thorin@tamu.edu
- >******************************************
-
-
- The system command expects a single string for a command. To do this
- with variable arguments requires that you create the string, and then
- pass the string into the system command. For example:
-
- char command[80];
- char *sitename; /* assumed to point to desired site name */
-
- sprintf(command, "ftp %s", sitename);
- system(command);
-
-
- Fletcher.Glenn@ov.com
-
-
-